home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Misc / NewFile / Source / Proto.m < prev    next >
Text File  |  1992-11-11  |  2KB  |  125 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "Proto.h"
  5.  
  6. @implementation Proto
  7.  
  8. + new:(char *)atypename:(char *)apathname:(char *)aneditor:(int)open
  9. {
  10.     return [[[[[self new]
  11.         setTypename:atypename]
  12.         setPathname:apathname]
  13.         setEditor:aneditor]
  14.         setDefaultopen:open];
  15. }
  16.  
  17. // Create a new proto by reading data from file.
  18. + read:(FILE *)fp
  19. {
  20.     id proto;
  21.     int    cont;
  22.     char    atypename[NAME_LENGTH], apathname[MAXPATHLEN], aneditor[NAME_LENGTH];
  23.     char    openstr[10];
  24.     int    open;
  25.     
  26.     cont = fscanf(fp, "typename = %[^,], pathname = %[^,], editor = %[^,], open = %s\n", atypename, apathname, aneditor, openstr);
  27.  
  28.     if (cont==4)
  29.     {
  30.         if (strcmp(openstr, WS_STR)==0)
  31.             open = OPEN_WS;
  32.         else if (strcmp(openstr, EDITOR_STR)==0)
  33.             open = OPEN_EDITOR;
  34.         else
  35.             open = DONT_OPEN;
  36.         
  37.         if (strcmp(aneditor, NULL_EDITOR)==0)
  38.             strcpy(aneditor, "");
  39.             
  40.         proto = [Proto new:atypename:apathname:aneditor:open];
  41.     }
  42.     else
  43.         proto = nil;
  44.     return proto;
  45. }
  46.  
  47. - (char *)typename
  48. {
  49.     return typename;
  50. }
  51.  
  52. - setTypename:(char *)str
  53. {
  54.     strcpy(typename, str);
  55.     return self;
  56. }
  57.  
  58. - (char *)pathname
  59. {
  60.     return pathname;
  61. }
  62.  
  63. - setPathname:(char *)str
  64. {
  65.     strcpy(pathname, str);
  66.     return self;
  67. }
  68.  
  69. - (char *)editor
  70. {
  71.     return editor;
  72. }
  73.  
  74. - setEditor:(char *)str
  75. {
  76.     strcpy(editor, str);
  77.     return self;
  78. }
  79.  
  80.  
  81. - (int)defaultopen
  82. {
  83.     return defaultopen;
  84. }
  85.  
  86. - setDefaultopen:(int)def
  87. {
  88.     defaultopen = def;
  89.     return self;
  90. }
  91.  
  92.  
  93. // The extension of the prototype file. Returns "" if there is no extension.
  94. - (char *)extension
  95. {
  96.     char *ext;
  97.     ext = rindex([self pathname], '.');
  98.     if (ext==0)
  99.         ext = "";
  100.     else
  101.         ext++;
  102.     return ext;
  103. }
  104.  
  105. - write:(FILE *)fp
  106. {
  107.     char *openstr, *aneditor;
  108.     int    open = [self defaultopen];
  109.     if (open == OPEN_EDITOR)
  110.         openstr = EDITOR_STR;
  111.     else if (open == OPEN_WS)
  112.         openstr = WS_STR;
  113.     else
  114.         openstr = DONT_STR;
  115.     
  116.     if (strcmp([self editor], "")==0)
  117.         aneditor = "/dev/null";
  118.     else
  119.         aneditor = [self editor];
  120.     fprintf(fp, "typename = %s, pathname = %s, editor = %s, open = %s\n", [self typename], [self pathname], aneditor, openstr);
  121.     return self;
  122. }
  123.  
  124. @end
  125.